<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="look">
            <button data-method="offset" data-type="auto" class="layui-btn " id="lookstyle" lay-event="look">查看</button>
        </script>
    </div>
</div>
{include file="public/footer" /}

<!--性别-->
<script type="text/html" id="sexTpl">
    {{#  if(d.sex === 2){ }}
    <span style="color: #F581B1;"> 女</span>
    {{#  } else { }}
    <span>男</span>
    {{#  } }}
</script>
<script type="text/html" id="typeTpl">
    {{#  if(d.type === 1){ }}
    <span style="color: #28f51d;">账号正常</span>
    {{# }else if(d.type === 2){ }}
    <span style="color: #f59b28;">合伙人</span>
    {{# }else if(d.type === 3){ }}
    <span style="color: #f42540;">账号封停</span>
    {{#  } else { }}
    <span style="color: rgba(0,0,0,0.11);">玩家退出</span>
    {{#  } }}
</script>
<script type="text/html" id="statusTpl">
    {{#  if(d.status === 1){ }}
    <span>未注册</span>
    {{# }else if(d.status === 2){ }}
    <span>已注册</span>
    {{# }else if(d.status === 3){ }}
    <span>未激活</span>
    {{# }else if(d.status === 4){ }}
    <span>等待审核</span>
    {{#  } else { }}
    <span>已激活</span>
    {{#  } }}
</script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/admin/team/getMember?memberCode={$memberCode}&active=ajax',
            method: 'post',
            parseData: function (res) { //res 即为原始返回的数据
                $('#countNum').html(res.data.info.total);
                $('#activated').html(res.data.statistics.activated);
                $('#notActive').html(res.data.statistics.notActive);
                $('#incomeTotal').html(res.data.statistics.total.incomeTotal);
                $('#goldTotal').html(res.data.statistics.total.goldTotal);
                $('#integralTotal').html(res.data.statistics.total.integralTotal);
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.info.total, //解析数据长度
                    "data": res.data.info.data, //解析数据列表
                };
            },
            defaultToolbar:'',
            cols: [[
                {field: 'name', title: '玩家名称', sort: false,},
                {field: 'code', title: '玩家ID', sort: false,minWidth:100},
                {field: 'phone', title: '手机号', sort: false,minWidth:120},
                {field: 'register_time', title: '注册日期', sort: false,minWidth:160},
                {field: 'levelTitle', title: '玩家等级', sort: false,},
                {field: 'teamTitle', title: '所属团队', sort: false},
                {field: 'sex', title: '性别', sort: false, templet: '#sexTpl'},
                {field: 'age', title: '年龄', sort: false,},
                {field: 'address', title: '地区', sort: false,},
                {field: 'income', title: '收益总额', sort: false,},
                {field: 'gold', title: '金币总额', sort: false,},
                {field: 'materials', title: '材料数量', sort: false,},
                {field: 'integral', title: '积分数量', sort: false,},
                {field: 'type', title: '玩家类型', sort: false, templet: '#typeTpl',},
                {field: 'status', title: '状态', sort: false, templet: '#statusTpl'},
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: false,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });


        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加用户',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/apply/qanswer_add',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            } else if (obj.event === 'LAYTABLE_TIPS') {
                alert('自定义的,不用的话可以将该方法删除')
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            var memberCode = obj.data.member_code;

            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/Index/page?view=table/edit',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                });
            }else  if (obj.event === 'look') {
                //触发事件  查看内容
                var index = layer.open({
                    title:'查看内容',
                    type: 2,
                    area: ['700px', '450px'],
                    shade:0.5,
                    shadeClose:true,
                    content: '/admin/team/getMember?memberCode='+memberCode,
                });

            }

        });

    });
</script>

</body>
</html>